import { createRouter, createWebHistory } from "vue-router";

const HelloWorld = () => import("@/components/HelloWorld.vue");

const routes = [
    {
        path: '/',
        redirect: "/home"
    },
    {
        path: '/home',
        name: 'Home',
        meta: {
            title: '首页',
            level: 1,//层级 控制切换动画
            isMenu: false//是否有侧边栏
        },
        component: () => import('@/views/home/home.vue'),
    },
    {
        path: '/exhibition',
        name: 'Exhibition',
        meta: {
            title: '首页',
            level: 2,
            isMenu: true
        },
        component: () => import('@/views/exhibition/exhibition.vue'),
    },
    {
        path: "/helloworld",
        name: "helloworld",
        meta: {
            title: "helloworld",
        },
        component: HelloWorld,
    },
];

const router = createRouter({
    history: createWebHistory('/competition-front/'),
    routes,
});

router.beforeEach((to, from, next) => {
    //console.log(to.meta.level, from.meta.level, to.meta.level < from.meta.level)
    //动态切换加载动画
    //to.meta.transition = 'move-right'
    to.meta.transition = to.meta.level < from.meta.level ? 'move-right' : to.meta.level > from.meta.level ? 'move-left' : 'fade'

    //if (getSessionData("userInfo")) {
    //    if (to.name === "Login") {
    //        // console.log(router);
    //        // debugger;
    //        return router.go(-1);
    //    }
    //} else {
    //    if (to.name === "Login") {
    //        return next();
    //    }
    //    return next("/login");
    //}
    next();
});


export default router;